package docqa

import (
	"oa-rest/common"
	log "github.com/sirupsen/logrus"
)

// DocQAService 文档问答服务
type DocQAService struct{}

// NewDocQAService 创建文档问答服务实例
func NewDocQAService() *DocQAService {
	return &DocQAService{}
}

// SelectAndAsk 选择文档并问答
func (s *DocQAService) SelectAndAsk(documentName, question string) (*SelectAndAskResponse, error) {
	// 构建请求数据
	requestData := map[string]interface{}{
		"document_name": documentName,
		"question":      question,
	}

	// 调用文档问答服务
	var response SelectAndAskResponse
	err := common.DocQAHttpClient.PostJSON("/select_and_ask", requestData, &response)
	if err != nil {
		log.Errorf("文档问答失败: %v", err)
		return nil, err
	}

	return &response, nil
}

// Ask 基于session_id的问答
func (s *DocQAService) Ask(sessionID, question string) (*AskResponse, error) {
	// 构建请求数据
	requestData := map[string]interface{}{
		"session_id": sessionID,
		"question":   question,
	}

	// 调用文档问答服务
	var response AskResponse
	err := common.DocQAHttpClient.PostJSON("/ask", requestData, &response)
	if err != nil {
		log.Errorf("文档问答失败: %v", err)
		return nil, err
	}

	return &response, nil
}